namespace SmartSoft.SystemForms
{
    using SmartSoft;
    using SmartSoft.Controls;
    using SmartSoft.ADP;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormDataLock : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnOk;
        private IContainer components;
        private GBoxControl gBoxControl;
        private TextDate txtNgay_Ks;

        public FormDataLock()
        {
            this.InitializeComponent();
            this.txtNgay_Ks.Value = AppInstance.EndingDateOfSubEnterprice;
            this.Text = AppInstance.SoftwareName;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.OnDo();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormDataLock));
            this.gBoxControl = new SmartSoft.Controls.GBoxControl();
            this.txtNgay_Ks = new SmartSoft.Controls.TextDate();
            this.btnCancel = new SmartSoft.Controls.BtnControl();
            this.btnOk = new SmartSoft.Controls.BtnControl();
            this.gBoxControl.SuspendLayout();
            this.SuspendLayout();
            // 
            // gBoxControl
            // 
            this.gBoxControl.Controls.Add(this.txtNgay_Ks);
            this.gBoxControl.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl.Location = new System.Drawing.Point(12, 12);
            this.gBoxControl.Name = "gBoxControl";
            this.gBoxControl.Size = new System.Drawing.Size(251, 76);
            this.gBoxControl.TabIndex = 0;
            this.gBoxControl.TabStop = false;
            this.gBoxControl.Text = "Khóa dữ liệu đến ngày";
            // 
            // txtNgay_Ks
            // 
            this.txtNgay_Ks.DateTimeFormat = SmartSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ks.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ks.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ks.Location = new System.Drawing.Point(86, 30);
            this.txtNgay_Ks.Mask = "00/00/0000";
            this.txtNgay_Ks.Name = "txtNgay_Ks";
            this.txtNgay_Ks.OldValue = null;
            this.txtNgay_Ks.Size = new System.Drawing.Size(78, 20);
            this.txtNgay_Ks.TabIndex = 0;
            this.txtNgay_Ks.Value = ((object)(resources.GetObject("txtNgay_Ks.Value")));
            // 
            // btnCancel
            // 
            this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnCancel.Location = new System.Drawing.Point(140, 103);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(75, 23);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "&Hủy bỏ";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // btnOk
            // 
            this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.btnOk.Font = new System.Drawing.Font("Arial", 8.25F);
            this.btnOk.Location = new System.Drawing.Point(59, 103);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(75, 23);
            this.btnOk.TabIndex = 1;
            this.btnOk.Text = "&Chấp nhận";
            this.btnOk.UseVisualStyleBackColor = true;
            this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
            // 
            // FormDataLock
            // 
            this.AcceptButton = this.btnOk;
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(275, 138);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOk);
            this.Controls.Add(this.gBoxControl);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "FormDataLock";
            this.ShowInTaskbar = false;
            this.gBoxControl.ResumeLayout(false);
            this.gBoxControl.PerformLayout();
            this.ResumeLayout(false);

        }

        private void OnDo()
        {
            AppInstance.EndingDateOfSubEnterprice = (DateTime) this.txtNgay_Ks.Value;
            new CompanyDataAccess().SetEndDate(AppInstance.Subsidiary, AppInstance.EndingDateOfSubEnterprice);
            base.Close();
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.OnDo();
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    }
}

